package com.hl.card.modular.pack.controller;

import com.hl.card.common.persistence.model.Goods;
import com.hl.card.common.util.ResponseObject;
import com.hl.card.modular.pack.service.RewardByCount;
import com.hl.card.modular.packBack.service.GoodsSevice;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * 信用卡奖励回调
 */
@RestController
public class CreditCardController {
    @Autowired
    private RewardByCount rewardByCount;
    @Resource
    private GoodsSevice goodsSevice;
    @RequestMapping(value = "/api/biBean/creditCardSend",method = RequestMethod.POST)
    public Object  creditCardSend(String userId,String orderId,String activated,String firstUsed){
        ResponseObject res = new ResponseObject();
        Map<Object, Object> map = new HashMap<>();
        if(activated.equals("P")){//发送激活的比豆
            String prodCode = "XYKJH";
            rewardByCount.makeCommunityAward(prodCode,userId,"0",orderId);
            Goods goods = goodsSevice.selectByCode(prodCode);
            String prodName = goods.getGoodsName();
            if(StringUtils.isBlank(prodName)) {
                map.put("code", "4");
                map.put("prodName", prodName);
                map.put("count", 0);
                map.put("statue", "0");
                map.put("msg", "该奖励在系统中不存在");
                System.out.println(prodName + "奖励在系统中不存在");
                res.setData(map);
                res.setErroCode(1);
                return res;
            }
        }
        if(firstUsed.equals("P")){//发送首刷的比豆
            String prodCode = "XYKSS";
            rewardByCount.makeCommunityAward(prodCode,userId,"0",orderId);
            Goods goods = goodsSevice.selectByCode(prodCode);
            String prodName = goods.getGoodsName();
            if(StringUtils.isBlank(prodName)) {
                map.put("code", "4");
                map.put("prodName", prodName);
                map.put("count", 0);
                map.put("statue", "0");
                map.put("msg", "该奖励在系统中不存在");
                System.out.println(prodName + "奖励在系统中不存在");
                res.setData(map);
                res.setErroCode(1);
                return res;
            }
        }
        return  "ok";
    }
}
